<%= javascript_include_tag "prototype" %>
<%= javascript_include_tag "util" %>
<%= javascript_include_tag "calendar" %>
<script language="javascript">
function showProductWindow(id)
{
    window.open("/product/product_info/"+id,"_blank","height=500,width=700,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}
function showAgentWindow(id)
{
    window.open("/other_org/agent_info/"+id,"_blank","height=500,width=500,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
}

function checkNum(flag, msg_id, obj_name, msg_text){
        if (flag) {
                if ($(obj_name).value == "" || ! digCheck($(obj_name).value))
                {
                        $(msg_id).innerText = msg_text;
                        $(msg_id).style.display = "block";
                        return false;
                }
                else return true;
        }
        else {
                $(msg_id).style.display = "none";
        }
}

function checkDate()
{
        if ( checkNum(true,'id_prefix','code_prefix','前缀输入错误')
                && checkNum(true,'id_from','code_from','起始编号输入错误')
                && checkNum(true,'id_to','code_to','结束编号输入错误')
                && checkNum(true,'id_postfix','code_postfix','后缀输入错误')
           )
                frmCode.submit();
}
</script>
<h1>订单管理 - <span id="secondHeading">查询条形码</span></h1>
<form id="input-form" name="frmCode" action="/query/code" method="post">
<TABLE border="0" id="INPUT_TABLE">
		<tr><td colspan="2">
			<% if @flash[:notice] -%>
					<div id="notice"><%= @flash[:notice] %></div>
				<% end -%>
                        <div class="errorExplanation" id="errorExplanation" style="display:none"><h2 id="errorExplanation_h2">发生1个错误</h2><ul><li id="errorExplanation_li"></li></ul></div>
			</td>
		</tr>
	<TR>
		<TD width="20%">前缀：</TD>
		<TD><input id="code_prefix"  type="text" name="prefix" size="30" maxlength="20" onfocus ="checkNum(false,'id_prefix')" onblur="checkNum(true,'id_prefix',this.id,'前缀输入错误')"/> <div class="redNsg" id="id_prefix" style="display:none;"></TD>
	</TR>
	<TR>
		<TD>起始编号：</TD>
		<TD><input id="code_from" type="text" name="from" size="30" maxlength="20" onfocus ="checkNum(false,'id_from')" onblur="checkNum(true,'id_from',this.id,'起始编号输入错误')"/> <div class="redNsg" id="id_from" style="display:none;"></TD>
        </TR>
	<TR>
		<TD>结束编号：</TD>
		<TD><input id="code_to" type="text" name="to" size="30" maxlength="20" onfocus ="checkNum(false,'id_to')" onblur="checkNum(true,'id_to',this.id,'结束编号输入错误')"/> <div class="redNsg" id="id_to" style="display:none;"></TD>
        </TR>
	<TR>
		<TD>后缀：</TD>
		<TD><input id="code_postfix" type="text" name="postfix" size="30" maxlength="20" onfocus ="checkNum(false,'id_postfix')" onblur="checkNum(true,'id_postfix',this.id,'后缀输入错误')"/> <div class="redNsg" id="id_postfix" style="display:none;"></TD>
	</TR>
	<TR>
		<TD colspan="2" align="right"><input type="button" class="sub" value="查询" onclick="checkDate()"></TD>
	</TR>
</TABLE>
</form>
<%if @codes%>
</p>
<TABLE border="0" id="LIST_TB">
	<TR id="LIST_TB_TITLE">
		<TD>条形码</TD>
		<TD>产品</TD>
		<TD>销售日期</TD>
		<TD>客户</TD>
	<TR>
	<%@codes.each do |code|%>
	<TR id="LIST_TB_CONTENT1">
		<TD><%=code.prefix+code.code+code.postfix%></TD>
		<TD><a href="javascript:showProductWindow(<%=code.product.id%>)"><%=code.product.name%></a></TD>
		<TD><%=code.out_date_at%></TD>
		<TD><a href="javascript:showAgentWindow(<%=code.agent.id%>)"><%=code.agent.name%></a></TD>
	</TR>
	<%end%>
</TABLE>
<table>
        <tr>
                <td>
                        <input type="button" value="打印当前页" class="sub" onclick="openPrintWindow('LIST_TB')"/>
                        <input type="button" value="导出当前数据" class="sub" onclick="CellAreaExcel('LIST_TB')"/>
                </td>
        </tr>
</table>
</form>
<%end%>
